﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Collections.Specialized;
using System.Data;


using Common;

using Castle.Core.Interceptor;
using Castle.DynamicProxy;

namespace com.globalwave.a8ext
{
    public class OrderDetailService : BaseService
    {
        private static NameValueCollection whereMap = null;
        private const string TABLE_NAME = "Order_Detail";

        
        public OrderDetailService()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
        public OrderDetailService(BaseService other)
            : base(other) 
        {
        }

        virtual public int create(NameValueCollection product)
        {
            return dao.insertTable(TABLE_NAME, product);
        }

        virtual public int update(NameValueCollection product)
        {
            NameValueCollection criterion = new NameValueCollection();
            string id = product.Get("order_detail_id");

            criterion.Add("order_detail_id", id);

            product.Remove("order_detail_id");

            NameValueCollection updateObject = new NameValueCollection();
            updateObject.Add("ext_num_1", product["ext_num_1"]);
            updateObject.Add("ext_num_2", product["ext_num_2"]);

            int result = dao.updateTable(TABLE_NAME, updateObject, criterion);

            product.Add("order_detail_id", id);

            return result;
        }

        virtual public int delete(NameValueCollection criterion)
        {
            if (criterion.Get("order_detail_id") != null)
            {
                throw new BaseException("E000001", "参数错误");
            }
            // delete cascade 
            //dao.deleteTable(TABLE_BULLETIN, criterion);
            //dao.deleteTable(TABLE_TOPIC, criterion);

            return dao.deleteTable(TABLE_NAME, criterion);

        }

        virtual public void deleteAll(string[] productIds)
        {
            if (productIds == null || productIds.Length == 0)
            {
                throw new BaseException("", "parames");
            }

            NameValueCollection criterion = new NameValueCollection();
            foreach (string productId in productIds)
            {
                criterion.Add("order_detail_ids", productId);
            }

            // delete cascade
            //dao.deleteTable(TABLE_BULLETIN, criterion);
            //dao.deleteTable(TABLE_TOPIC, criterion);

            dao.deleteTable(TABLE_NAME, criterion);

        }

        public NameValueCollection getWhereConfigMap()
        {
            if (whereMap != null)
            {
                return whereMap;
            }

            whereMap = new NameValueCollection();

            whereMap.Add("order_detail_ids", " order_detail_id in (@order_detail_ids) ");
            //whereMap.Add("FullName", " FullName like ? ");
            //whereMap.Add("UserCode", " UserCode like ? ");

            return whereMap;
        }

        public static OrderDetailService getInstance()
        {

            ProxyGenerator generator = new ProxyGenerator();

            return generator.CreateClassProxy<OrderDetailService>(new TransactionInterceptor());

        }
    }
}
